package com.zoffy.ybuhelper;

import android.annotation.SuppressLint;
import android.os.Bundle;
import android.view.MenuItem;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;
import androidx.viewpager2.adapter.FragmentStateAdapter;
import androidx.viewpager2.widget.ViewPager2;
import com.google.android.material.bottomnavigation.BottomNavigationView;
import com.google.android.material.navigation.NavigationBarView;
import com.zoffy.ybuhelper.fragment.HomeFragment;
import com.zoffy.ybuhelper.fragment.ToolFragment;
import org.jetbrains.annotations.NotNull;

import java.util.ArrayList;
import java.util.List;

public class MainActivity extends AppCompatActivity {

    private List<Fragment> fragments;

    @Override
    protected void onCreate(@Nullable @org.jetbrains.annotations.Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_navigator_base);
        setupViewPager();
    }

    private void setupViewPager(){
        fragments = new ArrayList<>();
        fragments.add(new ToolFragment());
        fragments.add(new HomeFragment());

        ViewPager2 pager2=findViewById(R.id.menu_pager2);
        pager2.setUserInputEnabled(false);
        pager2.setAdapter(new FragmentStateAdapter(this) {

            @NonNull
            @NotNull
            @Override
            public Fragment createFragment(int position) {
                return fragments.get(position);
            }

            @Override
            public int getItemCount() {
                return fragments.size();
            }
        });


        BottomNavigationView bottomNavigationView=findViewById(R.id.btm_nav);
        bottomNavigationView.inflateMenu(R.menu.bottom_menu);
        bottomNavigationView.setOnItemSelectedListener(new NavigationBarView.OnItemSelectedListener() {
            @SuppressLint("NonConstantResourceId")
            @Override
            public boolean onNavigationItemSelected(@NonNull @NotNull MenuItem item) {
                switch (item.getItemId()){
                    case R.id.tools:
                        pager2.setCurrentItem(0);
                        break;
                    case R.id.home:
                        pager2.setCurrentItem(1);
                        break;
                }
                return true;
            }
        });


    }
}
